<?php

namespace App\Http\Controllers\Admin;

use App\Service\HelperClass;
use Illuminate\Http\Request;
use App\Exceptions\ApiException;
use App\Http\Controllers\Controller;

class BaseController extends Controller
{
    protected $ip;
    protected $userId;
    protected $roleId;
    protected $isAdmin;
    protected $username;
    protected $requestArr;
    protected $requestFile;

    /**
     * 初始化方法
     * BaseController constructor.
     *
     * @param Request $request
     */
    public function __construct(Request $request)
    {
        // 获取传参数据
        $this->ip          = $request->ip();
        $this->requestArr  = $request->input();
        $this->requestFile = $request->file();

        //PS：这个需要给对应的key到前端生成，可以不用，直接用token校验即可
//        $sign = md5('appname=' . config('style.app.name') . '&appsecret=' . config('style.app.secret') . '&timestamp=' . $arr['timestamp']);
//        throw_if($arr['sign'] != $sign, new ApiException('用户登录信息异常'));

        // 获取管理员信息
        $admin          = HelperClass::getLoginAdmin();
        $this->userId   = $admin['id'];
        $this->roleId   = $admin['role_id'];
        $this->isAdmin  = $admin['is_admin'];
        $this->username = $admin['username'];

        return;
    }
}
